/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package akinator;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

public class ClockThread extends Thread {
    
    public JLabel label;
    private SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
    
    //Construtor recebe o jlabel onde será exibida a hora
    public ClockThread(JLabel label) {
        this.label = label;
    }

    
    //Atualiza o texto do label com a hora atual
    @Override
    public void run() {
        
        while (true) {
            
            label.setText("  Horário atual:  " + sdf.format(new Date()));
            
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(ClockThread.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            
        }
        
    }
    
}
